package cm.stu.dao;

import cm.stu.bean.Person;
import cm.stu.util.ConnectionFactory;

import java.sql.*;

public class TestDao1
{


    public static Person Login(Person p)
    {
        String sql = "select * from person where userAccount = '" + p.getUserAccount() + "' and userPassword ='" + p.getUserPassword() + "'";
        Connection connection = ConnectionFactory.getConnection();
        PreparedStatement pre = null;
        ResultSet res = null;
        Person newPerson = null;
        try {
            pre = connection.prepareStatement(sql);
            res = pre.executeQuery();
            while(res.next())
            {
                newPerson = new Person();
                newPerson.setUserAccount(res.getString("userAccount"));
                newPerson.setUserName(res.getString("userName"));
                newPerson.setUserSex(res.getString("userSex"));
                newPerson.setUserBirthday(res.getString("userBirthday"));
                newPerson.setUserIdCard(res.getString("userIdCard"));
                newPerson.setUserPassword(res.getString("userPassword"));
                newPerson.setUserIdentify(res.getInt("userIdentify"));
                newPerson.setUserOtherName(res.getString("userOtherName"));

            }


        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return newPerson;
    }


    public static void main(String[] args)
    {

        String driver = "com.mysql.cj.jdbc.Driver";//驱动就是一个类
        String url = "jdbc:mysql://localhost:3306/astu";
        String username = "root";
        String password = "miku39";


        try {
            //1.加载驱动
            Class.forName(driver);

            //2.创建连接
            Connection connection = DriverManager.getConnection(url, username, password);

            System.out.println("连接成功"+connection);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}